package com.yao.smy.controller;

import com.yao.smy.domain.VisitorDeviceRecord;
import com.yao.smy.service.VisitorDeviceRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/visitor-device-records")
public class VisitorDeviceRecordController {

    @Autowired
    private VisitorDeviceRecordService visitorDeviceRecordService;

    // 新增或更新访问记录
    @PostMapping
    public void saveVisitorDeviceRecord(@RequestBody VisitorDeviceRecord record) {
        visitorDeviceRecordService.addVisitorDeviceRecord(record);
    }

    // 根据ID删除访问记录
    @DeleteMapping("/{id}")
    public void deleteVisitorDeviceRecord(@PathVariable Long id) {
        visitorDeviceRecordService.deleteVisitorDeviceRecord(id);
    }

    // 根据ID查询访问记录
    @GetMapping("/{id}")
    public VisitorDeviceRecord getVisitorDeviceRecordById(@PathVariable Long id) {
        return visitorDeviceRecordService.getVisitorDeviceRecord(id);
    }

    // 查询所有访问记录
    @GetMapping
    public List<VisitorDeviceRecord> getAllVisitorDeviceRecords() {
        return visitorDeviceRecordService.getAllVisitorDeviceRecords();
    }

    // 根据游客身份证查询所有访问记录
    @GetMapping("/visitor/{visitorIdCard}")
    public List<VisitorDeviceRecord> getVisitorDeviceRecordsByVisitorIdCard(@PathVariable String visitorIdCard) {
        return visitorDeviceRecordService.getVisitorDeviceRecordsByVisitorIdCard(visitorIdCard);
    }

    // 根据设备IP查询所有被访问记录
    @GetMapping("/device/{deviceIp}")
    public List<VisitorDeviceRecord> getVisitorDeviceRecordsByDeviceIp(@PathVariable String deviceIp) {
        return visitorDeviceRecordService.getVisitorDeviceRecordsByDeviceIp(deviceIp);
    }
}